package com.cskaoyan.controller.profile;

import com.cskaoyan.model.bo.PageBo;
import com.cskaoyan.model.bo.profile.PasswordBo;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.PageListVo;
import com.cskaoyan.service.system.AdminService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: project-market
 * @description: 修改自己的密码
 * @author: Weiwei Liu
 * @create: 2021-12-03 21:10
 **/
@RestController
@RequestMapping("admin/profile")
public class ProfileController {

    @Autowired
    AdminService adminService;

    /**
     * 修改后台密码
     *
     * @param bo
     * @return
     */
    @PostMapping("password")
    public BaseRespVo password(@RequestBody PasswordBo bo) {

        if (!bo.getNewPassword().equals(bo.getNewPassword2())) return BaseRespVo.manual(605, "两次输入的密码不一致", null);

        String username = (String) SecurityUtils.getSubject().getSession().getAttribute("username");

        Integer i = adminService.password(bo, username);

        if (i == 0) return BaseRespVo.ok();

        else return BaseRespVo.manual(605, "密码错误", null);

    }

    /**
     * 后台通知，这个没有，自己先编一个
     *
     * @param bo
     * @return
     */
    @RequestMapping("lsnotice")
    public BaseRespVo lsnotice(PageBo bo, String title, String type) {

        // 此处真的没东西！！
        PageListVo vo = new PageListVo();
        vo.setLimit(bo.getLimit());

        return BaseRespVo.ok(vo);
    }


}
